package singleton;

public class Singleton {
    private static volatile Singleton instance;

    // 私有化构造方法，防止外部实例化
    private Singleton() {
    }

    // 提供全局访问点，，确保双重校验锁线程安全
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

    public void showMessage() {
        System.out.println("这是单例模式的实例");
    }
}
